package DB;


import Entity.Sale;

/** this class asks queries to get and insert sale's details from and into the db  */
public class SaleQuery {
	
	/**function which get pattern's details from db where pattern id like chosen*/
	public static String getPatternPerSale(String PatternID)
	{
		String str="SELECT * FROM pattern WHERE PatternID=" + "\"" + PatternID+ "\"";
		return str;
	}
	
	/**function which get selected worker's role details from db  */
	public static String getSalesWorkers()
	{
		String str="SELECT WorkerID FROM workers WHERE role=2";
		return str;
	}

	/**function which get selected parameters customer's id from db
	 * 
	 * @param MinAge
	 * @param MaxAge
	 * @param City
	 * @return
	 */
	public static String findCustomersInDB( int MinAge,int MaxAge, String City)
	{
		String str="SELECT CustomerID FROM customers WHERE City = " + "\""  + City + "\" AND Age BETWEEN " + "\"" + MinAge + "\" AND " + "\"" + MaxAge + "\"";
		return str;
	}

	/**function which insert customers history into db */
	public static String InsertCustomersHistoryQuery( String CustomerID, String SaleID, String salesman)
	{
		String str= "INSERT INTO cst_history (CustomerID,SaleID,WorkerID) VALUES ( \""+ CustomerID
				+ "\",\""
				+ SaleID
				+"\",\""
				+salesman
				+ "\")";

		return str;
	}
	
	/**function which get pattern's details from sale list*/
	public static String getPatternFromSaleList(String PatternID)
	{
		String str="SELECT * FROM sales WHERE PatternID=" + "\"" + PatternID+ "\"";
		return str;
	}

	/**function which get sale's details from sale list*/
	public static String getExistSaleQuery(String SaleID)
	{
		String str="SELECT * FROM sales WHERE SaleID=" + "\"" + SaleID + "\"";
		return str;
	}

	/**function which insert new sale into db */
	public static String InsertNewSale(String Saleid,String PatternID)
	{
		String str= "INSERT INTO sales (SaleID,PatternID) VALUES (\""
				+ Saleid
				+ "\",\""
				+ PatternID
				+ "\")";
				
		return str;
	}

	/**functions which check if a field is empty */
	public  boolean isEmpty(String field) 
	{
		if (field.isEmpty())
			return true;
		return false;
	}
	
	
	
}
